<?php 
	header("Content-Type: text/html; charset=utf-8");
	require_once(dirname(__FILE__) . '/' . 'SQLOperation.class.php');
	
	$db = new SQLOperation("localhost", "test");
	if ($db->connect()) {
		if (!empty($_POST['account']) && !empty($_POST['psw'])) {
			$psw = $_POST['psw'];
			$type = $_POST['type'];
			settype($type, "integer");
			$result = $db->query($type == 0 ? "register" : "server",
					"*",
					"account='".$_POST['account']."'");
			if ($result) {
				if (($row = mysql_fetch_array($result)) != NULL) {
					if (0 == strcasecmp($row['password'], $psw)) {
						if ($type == 1 && strlen($row['hospital']) == 0) {
							$arr = array("code"=>0, "msg"=>"success", "has_hospital"=>1);
						} else {
							$arr = array("code"=>0, "msg"=>"success");
						}
						echo json_encode($arr);
					} else {
						$arr = array("code"=>1, "msg"=>"conflict password");
						echo json_encode($arr);
					}
				} else {
					$arr = array("code"=>2, "msg"=>"account doesn't exist!");
					echo json_encode($arr);
				}				
			} else {
				$arr = array("code"=>100, "msg"=>mysql_error());
				echo json_encode($arr);
			}
		}
	
		$db->close();
	} else {
		$arr = array("code"=>100, "msg"=>mysql_error());
		echo json_encode($arr);
	}
?>